package com.yanqu.road.server.cmd.vehiclesoul;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleSoulModule;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;


@Cmd(code = Protocol.S_VSOUL_COMPOSE_ONEKEY, desc = "一键魂石合成")
public class VehicleOneKeyComposeSoulCmd extends AbstractCommand {

	private int quality;
	private int num;
	private boolean lockColor;
	private boolean isLoop;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		VehicleProto.VehicleSoulOneKeyComposeReqMsg reqMsg = VehicleProto.VehicleSoulOneKeyComposeReqMsg.parseFrom(packet.getBytes());
		quality = reqMsg.getQuality();
		num = reqMsg.getNum();
		lockColor = reqMsg.getLockColor();
		isLoop = reqMsg.getIsLoop();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(VehicleSoulModule.class).composeSoulOneKey(quality,num,lockColor,isLoop);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			VehicleProto.VehicleSoulOneKeyComposeRespMsg.Builder respMsg = VehicleProto.VehicleSoulOneKeyComposeRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_VSOUL_COMPOSE_ONEKEY, respMsg);
		}
	}

}
